﻿using System;
using iTeamyou.LTS.Core.Services;
using Microsoft.EntityFrameworkCore;

namespace iTeamyou.LTS.Core.Models
{
	public class SSODBContext : DbContext
	{
        public SSODBContext(){}

        public SSODBContext(DbContextOptions<SSODBContext> options) : base(options){}

        public DbSet<LoginUser> LoginUsers { get; set; }
        public DbSet<LoginApp> Apps { get; set; }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity<LoginApp>().HasNoKey();
            builder.Entity<LoginUser>().HasKey(t => new { t.Id, t.AppCode });
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                var shareService = new SharedService();
                //optionsBuilder.UseMySql("server=localhost; userid=root; password=111qqq!; port=3306; database=lts; sslmode=Required;", new MySqlServerVersion(new Version()));
                optionsBuilder.UseMySql(shareService.GetConnectionString("SSODB"), new MySqlServerVersion(new Version()));
            }
        }
    }
}

